{
 "metadata": {
  "name": "",
  "signature": "sha256:ef330f63ab710fd8388ebffaabad155436f94171ada6cad2c7c3429441728e17"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "# Zhenfeng Liang"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "# MTH9879 Homework 5\n",
      "\n",
      "Assigned: March 3, 2015.\n",
      "Due: March 17, 2015 by 6pm. \n",
      "\n",
      "Late homework **will not be accepted**.\n",
      "\n",
      "$$\n",
      "\\newcommand{\\supp}{\\mathrm{supp}}\n",
      "\\newcommand{\\E}{\\mathbb{E}}\n",
      "\\newcommand{\\Eof}[1]{\\mathbb{E}\\left[ #1 \\right]}\n",
      "\\def\\Cov{{ \\mbox{Cov} }}\n",
      "\\def\\Var{{ \\mbox{Var} }}\n",
      "\\newcommand{\\1}{\\mathbf{1} }\n",
      "\\newcommand{\\PP}{\\mathbb{P} }\n",
      "%\\newcommand{\\Pr}{\\mathrm{Pr} }\n",
      "\\newcommand{\\QQ}{\\mathbb{Q} }\n",
      "\\newcommand{\\RR}{\\mathbb{R} }\n",
      "\\newcommand{\\DD}{\\mathbb{D} }\n",
      "\\newcommand{\\HH}{\\mathbb{H} }\n",
      "\\newcommand{\\spn}{\\mathrm{span} }\n",
      "\\newcommand{\\cov}{\\mathrm{cov} }\n",
      "\\newcommand{\\sgn}{\\mathrm{sgn} }\n",
      "\\newcommand{\\HS}{\\mathcal{L}_{\\mathrm{HS}} }\n",
      "%\\newcommand{\\HS}{\\mathrm{HS} }\n",
      "\\newcommand{\\trace}{\\mathrm{trace} }\n",
      "\\newcommand{\\LL}{\\mathcal{L} }\n",
      "%\\newcommand{\\LL}{\\mathrm{L} }\n",
      "\\newcommand{\\s}{\\mathcal{S} }\n",
      "\\newcommand{\\ee}{\\mathcal{E} }\n",
      "\\newcommand{\\ff}{\\mathcal{F} }\n",
      "\\newcommand{\\hh}{\\mathcal{H} }\n",
      "\\newcommand{\\bb}{\\mathcal{B} }\n",
      "\\newcommand{\\dd}{\\mathcal{D} }\n",
      "\\newcommand{\\g}{\\mathcal{G} }\n",
      "\\newcommand{\\p}{\\partial}\n",
      "\\newcommand{\\half}{\\frac{1}{2} }\n",
      "\\newcommand{\\T}{\\mathcal{T} }\n",
      "\\newcommand{\\bi}{\\begin{itemize}}\n",
      "\\newcommand{\\ei}{\\end{itemize}}\n",
      "\\newcommand{\\beq}{\\begin{equation}}\n",
      "\\newcommand{\\eeq}{\\end{equation}}\n",
      "\\newcommand{\\beas}{\\begin{eqnarray*}}\n",
      "\\newcommand{\\eeas}{\\end{eqnarray*}}\n",
      "\\newcommand{\\cO}{\\mathcal{O}}\n",
      "\\newcommand{\\cF}{\\mathcal{F}}\n",
      "\\newcommand{\\cL}{\\mathcal{L}}\n",
      "\\newcommand{\\BS}{\\text{BS}}\n",
      "$$"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "<font color = \"red\">Homework is to be done by each student individually.  To receive full credit, you must email a completed copy of this iPython notebook to Yu Gan (yugan323@gmail.com), Fubo Shi (fubo.shi.baruch@gmail.com), and Tai-Ho Wang (tai-ho.wang@baruch.cuny.edu) by the due date and time.  All R-code must run correctly and solutions must be written up neatly in Markdown/LaTeX format.\n",
      "\n",
      "<font color=\"blue\">If you encounter problems with Markdown/LaTeX or iPython notebook, please contact your TAs Yu Gan and/or Fubo Shi.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "### 0. (0 points) \n",
      "Read Chapter 7 of Hasbrouck, Chapters 4 and 5 of Foucault, Pagano and R&ouml;ell, and Section 3 of Bouchaud, Farmer and Lillo."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## The Kyle (1985) model"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "### 1. (14 points)\n",
      "\n",
      "Suppose that the monopolistic trader in the Kyle (1985) model is not told the true value $\\tilde S$ but is instead given a signal $x=\\tilde S+\\epsilon$ with $\\epsilon \\sim N(0,\\sigma_\\epsilon^2)$, where $\\tilde S$ and $\\epsilon$ are assumed independent.\n",
      "\n",
      "(a) Compute the conditional expectation $\\mathbb{E}[\\tilde S|x]$.\n",
      "\n",
      "(b) If $\\mathcal I$ assumes that the market maker $\\mathcal M$ generates a price function of the form $p=\\mu +\\lambda\\,y$, show that the informed trader's optimal (profit maximizing) demand is given by\n",
      "\n",
      "$$\n",
      "y_i=\\frac{\\phi}{2\\,\\lambda}\\,\\left(x-\\mu\\right)\n",
      "$$\n",
      "\n",
      "where\n",
      "\n",
      "$$\n",
      "\\phi = \\frac{\\sigma^2}{\\sigma^2+\\sigma_\\epsilon^2}.\n",
      "$$\n",
      "\n",
      "(c) Following the derivation from the lecture slides, use the result of (b) to deduce equation (11) in the lecture slides:\n",
      "\n",
      "$$\n",
      "\\lambda=\\frac{\\sigma}{2\\,\\sigma_u}\\,\\sqrt{\\phi}.\n",
      "$$\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## Solution\n",
      "\n",
      "### (a)\n",
      "\n",
      "From the Kyle model, we know $\\tilde S \\sim N(\\mu,\\sigma^2).$\n",
      "\n",
      "If we condition on $\\tilde S$, $\\tilde S$ is fixed and would not bring in variance. So,\n",
      "$x \\sim N(\\tilde S, \\sigma_\\epsilon^2 + \\sigma^2), x|\\tilde S \\sim N(\\tilde S,\\sigma_\\epsilon^2)$ \n",
      "\n",
      "From Kalman filter,\n",
      "$$ \\tilde S|x \\sim N(\\phi\\,x+(1-\\phi)\\,\\mu,(1-\\phi)\\,\\sigma^2)$$\n",
      "\n",
      "where\n",
      "\n",
      "$$ \\phi=\\frac{\\tau_{x|\\tilde S}}{\\tau_{\\tilde S}+\\tau_{x|\\tilde S}} $$ \n",
      "$$ \\tau_{x | \\tilde S} = \\frac{1}{\\sigma_\\epsilon^2}$$\n",
      "$$ \\tau_{\\tilde S} = \\frac{1}{\\sigma^2} $$\n",
      "\n",
      "So,\n",
      "$$\n",
      "\\phi = \\frac{\\sigma^2}{\\sigma^2+\\sigma_\\epsilon^2}.\n",
      "$$\n",
      " "
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "### (b)\n",
      "\n",
      "We need to maximize expected payoff,\n",
      "$$\\mathbb{E} [y_i\\,(\\tilde S-p(y))| x] \\\\\n",
      " = \\mathbb{E} [y_i\\,(\\tilde S-p(y))| x] \\\\\n",
      " = \\mathbb{E} [y_i\\,(\\tilde S- \\mu - \\lambda(y_i + y_u))|x] \\\\\n",
      " = y_i\\,(\\phi\\,x+(1-\\phi)\\,\\mu - \\mu-\\lambda\\,y_i) \\\\\n",
      " = -\\lambda y_i^2 + \\phi(x - \\mu)y_i$$\n",
      "\n",
      "which is a quadratic function, when $y_i = \\frac{\\phi(x - \\mu)}{2\\lambda}$, the expected payoff is maximized, which is what we wanted to show."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "### (C)\n",
      "\n",
      "Market maker would assume the demand function of the informed traders, $y_i = a + bx $\n",
      "\n",
      "From the note, we see,\n",
      "$$\n",
      "y_i=\\frac{\\phi}{2\\,\\lambda}\\,\\left(x-\\mu\\right) = a + bx \n",
      "$$\n",
      "Then, we have,\n",
      "$$\n",
      "a = -\\frac{\\mu \\phi}{2 \\lambda}, b = \\frac{\\phi}{2 \\lambda}\n",
      "$$\n",
      "\n",
      "Given a total demand order from the market, the price that the market maker offers should be equal to the expected conditional price. $p(y) = \\mu + \\lambda y = E(\\tilde S | y)$\n",
      "\n",
      "We know from the note, $\\lambda = \\frac{Cov(\\tilde S, y)}{Var(y)}$, where,\n",
      "$$\n",
      "Cov(\\tilde S, y) = Cov(\\tilde S, y_i + y_u) = Cov(\\tilde S, a + b \\tilde S + b \\epsilon) = b \\sigma^2\n",
      "$$\n",
      "$$\n",
      "Var(y) = Var(y_i + y_u) = \\sigma_u^2 + b^2(\\sigma^2 + \\sigma_{\\epsilon}^2)\n",
      "$$\n",
      "\n",
      "So, solve equtions system by substituting $b$,\n",
      "$$\n",
      "\\lambda = \\frac{b \\sigma^2}{\\sigma_u^2 + b^2(\\sigma^2 + \\sigma_{\\epsilon}^2)} = \\frac{b}{\\frac{\\sigma_u^2}{\\sigma^2} + b^2 \\phi^{-1}} \n",
      "$$\n",
      "$$\n",
      "b = \\frac{\\phi}{2 \\lambda} \n",
      "$$\n",
      "We get,\n",
      "$$\n",
      "\\lambda^2 = \\frac{\\sigma^2 \\phi}{4 \\sigma_u^2}\n",
      "$$\n",
      "So,\n",
      "$$\n",
      "\\lambda = \\frac{\\sigma \\sqrt{\\phi}}{2 \\sigma_u}\n",
      "$$\n",
      "which is what we need to show.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "### 2. (2 points) \n",
      "In the Kyle model, if the characteristic uninformed demand $\\sigma_u$ increases by some factor $\\theta$, what happens to the optimal informed trader demand $y_i$?"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## Solution\n",
      "\n",
      "From the note, we know,\n",
      "\n",
      "$$\n",
      "y_i = \\frac{(\\tilde S - \\mu)\\sigma_u}{\\sigma}\n",
      "$$\n",
      "\n",
      "From the formula, we can see $y_i$ is a linear function with $\\sigma_u$, so when $\\sigma_u$ increases by some factor $\\theta$, $y_i$ should increase $theta$ as well. It means when the uninformed traders trade with more volatility, the informed traders can make more money from it so they have more demand."
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "### 3. (6 points) \n",
      "\n",
      "As in Exercise 7.3 of Hasbrouck (but with different notation), suppose that a broker $\\mathcal P$ spots an insider and decides to submit his own piggyback orders.  Specifically, if $\\mathcal I$ submits demand $y_i$, $\\mathcal P$ submits demand $\\gamma\\,y_i$ with $\\gamma>0$.\n",
      "\n",
      "(a) Assuming that $\\mathcal I$ can detect how much piggyback order flow there is, deduce that the equilibrium Kyle lambda is unchanged from the original case where there are no piggyback orders.\n",
      "\n",
      "(b) Derive expressions for $\\mathcal I$'s optimal demand $y_i$ and his expected P&L.\n",
      "\n",
      "(c) Explain to a non-expert what happens to your trade capacity and your profitability if someone is piggybacking on your trades.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "## Solution\n",
      "\n",
      "### (a)\n",
      "The expected payoff should be,\n",
      "$$\n",
      "E(y_i(\\tilde S - \\mu - \\lambda((1 + \\gamma)y_i + y_u)) | \\tilde S) \\\\\n",
      "= y_i(\\tilde S - \\mu - \\lambda(1 + \\gamma)y_i) \\\\ \n",
      "= -\\lambda(1 + \\gamma)y_i^2 + (\\tilde S - \\mu)y_i\n",
      "$$\n",
      "\n",
      "When $y_i = \\frac{\\tilde S - \\mu}{2\\lambda (1 + \\gamma)}$, the expected payoff is maximized. \n",
      "\n",
      "As usual, we let $y_i = \\frac{\\tilde S - \\mu}{2\\lambda (1 + \\gamma)} = a + b\\tilde S$. We have,\n",
      "\n",
      "$$\n",
      "a = \\frac{-\\mu}{2\\lambda(1 + \\gamma)},  b = \\frac{1}{2\\lambda(1 + \\gamma)}\n",
      "$$\n",
      "\n",
      "From the note, we know,\n",
      "$$\n",
      "\\lambda = \\frac{Cov(\\tilde S, y)}{Var(y)} = \\frac{(1 + \\gamma)b\\sigma^2}{(1 + \\gamma)^2 b^2 \\sigma^2 + \\sigma_u^2}\n",
      "$$\n",
      "\n",
      "We plug $b = \\frac{1}{2\\lambda(1 + \\gamma)}$ in and found all $(1 + \\gamma)$ terms are cancelled out. We can see we would have the exact term as the original case.\n"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "### (b)\n",
      "\n",
      "We derived in part (a),\n",
      "$$\n",
      "y_i = \\frac{\\tilde S - \\mu}{2\\lambda (1 + \\gamma)}\n",
      "$$\n",
      "\n",
      "We know $\\lambda = \\frac{\\sigma}{2\\sigma_u}$. The expected P&L is,\n",
      "\n",
      "$$\n",
      "E(PayOff) =  \\frac{\\tilde S - \\mu}{2\\lambda (1 + \\gamma)}(\\tilde S - \\mu - \\lambda(1 + \\gamma) \\frac{\\tilde S - \\mu}{2\\lambda (1 + \\gamma)}) \\\\\n",
      "= \\frac{(\\tilde S - \\mu)^2}{2(1 + \\gamma)} * \\frac{\\sigma_u}{\\sigma}\n",
      "$$"
     ]
    },
    {
     "cell_type": "markdown",
     "metadata": {},
     "source": [
      "### (c)\n",
      "\n",
      "When there is some piggyback orders, the marginal benefit for each order becomes negative from zero. In order to turn the marginal benefit back to zero, i.e, maximize its benefit, the informed traders need to decrease their own trades. \n",
      "\n",
      "When there is some piggyback orders which is a percent of $y_i$, it is like that the maket have as much as $(1 + \\gamma)$ times the number of original informed traders. So, each informed trader's profit will be the $\\frac{1}{1 + \\gamma}$ times the original profit."
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}